<template>
  <div class="home container-fluid">
    <div class="row">
      <div class="col-xs-12 text-center title">
        <span class="title-text">欢迎来到DISC测试</span>
      </div>
      <div class="col-xs-12 uesr-info">
        <form>
          <div class="form-group">
            <label>姓名</label>
            <input v-model="username" type="text" class="form-control" placeholder="请输入您的姓名">
          </div>
          <div class="form-group">
            <label>电话</label>
            <input v-model="phone" type="text" class="form-control" placeholder="请输入您的电话">
          </div>
          <div class="form-group">
            <label>邮箱</label>
            <input v-model="email" type="text" class="form-control" placeholder="请输入您的邮箱">
          </div>
        </form>
      </div>
      <div class="start text-center">
        <button
          @click="start"
          type="button"
          class="btn btn-info btn-lg"
          style="background-color: #23b7b7;"
        >开始测试</button>
      </div>
    </div>
  </div>
</template>

<script>
import { Message } from "element-ui";
export default {
  name: "home",
  data() {
    return {
      username: "",
      phone: "",
      email: ""
    };
  },
  methods: {
    start() {
      if(this.username == '' || this.phone == '' || this.email == ''){
        alert("别着急，请填写基本信息哦")
        return;
      }
      let params = new URLSearchParams();
      params.append("username", this.username);
      params.append("phone", this.phone);
      params.append("email", this.email);
      this.$axios
        .post("/user/add.wy", params)
        .then(res => {
          console.log(res);
          let userInfo = { userUUID: res.data, username: this.username };
          sessionStorage.setItem("userInfo", JSON.stringify(userInfo));
          this.$router.push({
            path: "/topic"
          });
        })
        .catch(err => {
          Message.error("未知错误");
        });
    }
  }
};
</script>

<style scope>
.title {
  padding-top: 35%;
}
.title-text {
  font-size: 28px;
  color: #23b7b7;
  font-weight: 600;
}
.uesr-info {
  padding-top: 10%;
}
.uesr-info label {
  font-weight: 475;
}
</style>
